const { spawn } = require('child_process');
const iconv = require('iconv-lite')

const ls = spawn('java', ['-help'],{encoding : 'buffer'});

ls.stdout.on('data', (data) => {
  console.log("stdout: "+data.isEncoding("UTF-8"));
});

ls.stderr.on('data', (data) => { // buffer不支持GB编码
    console.log("stderr: "+iconv.decode(data, 'GB2312'));
});

ls.on('close', (code) => {
  console.log(`子进程退出，使用退出码 ${code}`);
});